from ninja import Schema, Field
from pydantic import BaseModel, root_validator, validator
from typing import List, Optional


class Action(Schema):
    servo_id: int = Field(ge=1, le=18, title='舵机id', description='范围为1-18')
    pulse: int = Field(ge=0, le=1000, title='转动角度', description='范围为0-1000')
    use_time: int = Field(500, ge=0, le=30000, title='使用时间(单位为ms)', description='')

    class Config:
        title = '动作参数'


class ActionListSchemaIn(Schema):
    action_lst: List[Action] = Field(title='一串动作')

    class Config:
        title = '动作数组参数'
        schema_extra = {
            "example": {
                "action_lst": [
                    {"servo_id": 1, "pulse": 100, "use_time": 500},
                    {"servo_id": 2, "pulse": 400, "use_time": 500},
                    {"servo_id": 3, "pulse": 200, "use_time": 500},
                    {"servo_id": 4, "pulse": 100, "use_time": 500},
                    {"servo_id": 5, "pulse": 500, "use_time": 500},
                    {"servo_id": 6, "pulse": 500, "use_time": 500},
                    {"servo_id": 7, "pulse": 500, "use_time": 500},
                    {"servo_id": 8, "pulse": 500, "use_time": 500},
                    {"servo_id": 9, "pulse": 500, "use_time": 500},
                    {"servo_id": 10, "pulse": 500, "use_time": 500},
                    {"servo_id": 11, "pulse": 500, "use_time": 500},
                    {"servo_id": 12, "pulse": 500, "use_time": 500},
                    {"servo_id": 13, "pulse": 500, "use_time": 500},
                    {"servo_id": 14, "pulse": 500, "use_time": 500},
                    {"servo_id": 15, "pulse": 500, "use_time": 500},
                    {"servo_id": 16, "pulse": 500, "use_time": 500},
                    {"servo_id": 17, "pulse": 500, "use_time": 500},
                    {"servo_id": 18, "pulse": 500, "use_time": 500}
                ]
            }
        }


class ActionGroupSchemaIn(Schema):
    file_name: str = Field(title='动作组文件名')

    class Config:
        title = '动作数文件'
        schema_extra = {
            "example": {
                "file_name": 'bow'
            }
        }


class HandleControlSchemaIn(Schema):
    action: str = Field(title='手柄动作')

    class Config:
        title = '手柄动作'
        schema_extra = {
            "example": {
                "action": 'go'
            }
        }


class ServoListSchemeIn(Schema):
    servo_lst: List[int] = Field(title='舵机数组')

    class Config:
        title = '舵机数组'
        schema_extra = {
            "example": {
                "servo_lst": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
            }
        }
